/*
https://leetcode-cn.com/problems/minimum-swaps-to-make-sequences-increasing/solution/shi-xu-lie-di-zeng-de-zui-xiao-jiao-huan-ci-shu-by/
 */
public class Solution801 {
    public int minSwap(int[] nums1, int[] nums2) {
        int a=0,b=1;
        for (int i=1;i<nums1.length;i++){
            int c=Integer.MAX_VALUE,d=Integer.MAX_VALUE;
            if (nums1[i]>nums1[i-1] && nums2[i]>nums2[i-1]){
                c=Math.min(c,a);
                d=Math.min(d,b+1);
            }
            if (nums1[i-1]<nums2[i] && nums2[i-1]<nums1[i]){
                c=Math.min(c,b);
                d=Math.min(d,a+1);
            }
            a=c;
            b=d;
        }
        return Math.min(a,b);
    }

    public static void main(String[] args) {
        System.out.println(new Solution801().minSwap(new int[]{1,3,5,4},new int[]{1,2,3,7}));
    }
}
